* ANES analysis for: 
* Class, Policy Attitudes and U.S. Presidential Voting in the Post-Industrial Era: The Importance of Issue Salience
* Franko & Witko
* Political Research Quarterly
* Date: 05/25/22


set more off


*******************************************************************************
* Policy effect on vote.
* Pooled models.
*******************************************************************************

* Create new frame to save results.
frame create dvotepol_diffs_anes
frame dvotepol_diffs_anes { 
	input 	str10 var diff ll ul str10 sample
		"jobs01" . . . "All"
		"culpol01" . . . "All"
		"racepol01" . . . "All"
		"jobs01" . . . "White"
		"culpol01" . . . "White"
		"racepol01" . . . "White"
		"jobs01" . . . "Nonwhite"
		"culpol01" . . . "Nonwhite"
	end
}

*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "pid7 polviews white age female south"

foreach v in jobs01 culpol01 racepol01 {
	melogit demvote `v' `varlst1' || year: 
	estimates store dvp_`v'_anes_all
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_anes { 
		replace diff = r(estimate) if var == "`v'" & sample == "All"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "All"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "All"
	}
}


*******************************************************************************
* Repeat above analysis for white only subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in jobs01 culpol01 racepol01 {
	melogit demvote `v' `varlst2' if white==1 || year: 
	estimates store dvp_`v'_anes_wo
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_anes { 
		replace diff = r(estimate) if var == "`v'" & sample == "White"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "White"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "White"
	}
}


*******************************************************************************
* Repeat above analysis for nonwhite subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in jobs01 culpol01 {
	melogit demvote `v' `varlst2' if white==1 || year: 
	estimates store dvp_`v'_anes_nwo
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_anes { 
		replace diff = r(estimate) if var == "`v'" & sample == "Nonwhite"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "Nonwhite"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "Nonwhite"
	}
}


***** Save Min/max difference results.
frame dvotepol_diffs_anes : save "results/dvotepol_diffs_anes.dta", replace



*******************************************************************************
* Allow policy coefficients to vary by year, then plot effects over time.
*******************************************************************************

*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "pid7 polviews white age female south"

foreach v in jobs01 culpol01 racepol01 {
	melogit demvote `v' `varlst1' || year: `v' 
	estimates store dvp_`v'_anes_time
	* Estimated effects: use coefficients.
	preserve
	predict b_re* if e(sample), reffects reses(b_rese*)

	gen b = _b[`v'] + b_re1
	gen se = sqrt((_se[`v']^2) + (b_rese1^2))

	collapse b se, by(year)
	gen b_hi = b + 1.96*se
	gen b_lo = b - 1.96*se

	drop if b == .
	gen str20 var = "`v'"

	save "results/dvp_`v'_anes_time.dta", replace
	restore
}


*******************************************************************************
* Repeat above analysis for white only subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in jobs01 culpol01 racepol01 {
	melogit demvote `v' `varlst2' if white==1 || year: `v' 
	estimates store dvp_`v'_anes_time_wo
	* Estimated effects: use coefficients.
	preserve
	predict b_re* if e(sample), reffects reses(b_rese*)

	gen b = _b[`v'] + b_re1
	gen se = sqrt((_se[`v']^2) + (b_rese1^2))

	collapse b se, by(year)
	gen b_hi = b + 1.96*se
	gen b_lo = b - 1.96*se

	drop if b == .
	gen str20 var = "`v'"

	save "results/dvp_`v'_anes_time_wo.dta", replace
	restore
}




preserve
clear
append using "results/dvp_jobs01_anes_time.dta" 
append using "results/dvp_culpol01_anes_time.dta" 
append using "results/dvp_racepol01_anes_time.dta" 
save "results/dvote_policy_anes_time.dta", replace
restore

preserve
clear
append using "results/dvp_jobs01_anes_time_wo.dta" 
append using "results/dvp_culpol01_anes_time_wo.dta" 
append using "results/dvp_racepol01_anes_time_wo.dta" 
save "results/dvote_policy_anes_time_wo.dta", replace
restore


